package com.xueyi.game.backend.controller;

import com.xueyi.core.base.BaseBackController;
import com.xueyi.core.base.BaseResponse;
import com.xueyi.core.base.annotation.Add;
import com.xueyi.core.base.annotation.Update;
import com.xueyi.game.backend.entity.dto.*;
import com.xueyi.game.backend.entity.vo.BaseSelectVo;
import com.xueyi.game.backend.entity.vo.FindRoleListVo;
import com.xueyi.game.backend.service.IBackendRoleService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @authoer: hxs
 * @createDate: 2022/11/9 09:31
 * @description: 角色管理接口
 */
@RestController
@AllArgsConstructor
public class BaseRoleController extends BaseBackController {

    private final IBackendRoleService backendRoleService;


    /**
     * 获取角色列表
     *
     * @param findRoleListReq
     * @return
     * @author hxs
     */
    @GetMapping("/role/findRoleList")
    public BaseResponse<FindRoleListVo> findRoleList(@Validated FindRoleListDto findRoleListReq) {
        return BaseResponse.success(backendRoleService.findRoleList(findRoleListReq));
    }

    /**
     * 新增角色
     *
     * @param addOrUpdateRoleReq
     * @return
     * @author hxs
     */
    @PostMapping("/role/addRole")
    public BaseResponse<Boolean> addRole(@Validated(Add.class) @RequestBody AddOrUpdateRoleDto addOrUpdateRoleReq) {
        backendRoleService.addRole(addOrUpdateRoleReq);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 修改角色
     *
     * @param addOrUpdateRoleReq
     * @return
     * @author hxs
     */
    @PostMapping("/role/updateRole")
    public BaseResponse<Boolean> updateRole(@Validated(Update.class) @RequestBody AddOrUpdateRoleDto addOrUpdateRoleReq) {
        backendRoleService.updateRole(addOrUpdateRoleReq);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 修改角色的状态
     *
     * @param changeRoleStatusReq
     * @return
     * @author hxs
     */
    @PostMapping("/role/changeRoleStatus")
    public BaseResponse<Boolean> changeRoleStatus(@Validated @RequestBody ChangeRoleStatusDto changeRoleStatusReq) {
        backendRoleService.changeRoleStatus(changeRoleStatusReq);
        return BaseResponse.success(Boolean.TRUE);
    }

    /**
     * 为角色关联权限
     *
     * @param bindJurisdictionForRoleReq
     * @return
     * @author hxs
     */
    @PostMapping("/role/bindJurisdictionForRole")
    public BaseResponse<Boolean> bindJurisdictionForRole(@Validated @RequestBody BindJurisdictionForRoleDto bindJurisdictionForRoleReq) {
        backendRoleService.bindJurisdictionForRole(bindJurisdictionForRoleReq);
        return BaseResponse.success(Boolean.TRUE);
    }


    /**
     * 通过角色id获取该角色的权限id列表
     *
     * @param findJurisdictionListByRoleIdReq
     * @return
     * @author hxs
     */
    @GetMapping("/role/findJurisdictionListByRoleId")
    public BaseResponse<String> findJurisdictionListByRoleId(@Validated FindJurisdictionListByRoleIdDto findJurisdictionListByRoleIdReq) {
        String ids = backendRoleService.findJurisdictionListByRoleId(findJurisdictionListByRoleIdReq);
        return BaseResponse.success(ids);
    }

    /**
     * 获取所有的角色（下拉菜单用）
     *
     * @return
     * @author hxs
     */
    @GetMapping("/role/findAllRoleSelectVo")
    public BaseResponse<List<BaseSelectVo>> findAllRoleSelectVo() {
        List<BaseSelectVo> response = backendRoleService.findAllRoleSelectVo();
        return BaseResponse.success(response);
    }
}
